package com.example.smssender;

import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.app.Dialog;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.android.material.textfield.TextInputEditText;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

/**
 * 已选择联系人详情对话框（BottomSheet）
 * 支持搜索、分组、批量操作
 */
public class SelectedContactsBottomSheetDialog extends BottomSheetDialogFragment {
    
    private static final String TAG = "SelectedContactsBS";
    
    private RecyclerView rvContacts;
    private TextInputEditText etSearch;
    private TextView tvStats;
    private TextView tvSelectedCountBottom;
    private Button btnSelectAll;
    private Button btnClearAll;
    private Button btnConfirm;
    private Button btnCancel;
    
    private ContactBottomSheetAdapter adapter;
    private List<Contact> allContacts;
    private List<Contact> filteredContacts;
    private Set<String> selectedContactIds; // 使用ID+电话号码组合作为唯一键
    private OnContactsChangedListener listener;
    
    /**
     * 生成联系人的唯一键（ID+电话号码），用于精确匹配
     * 这样可以处理多个联系人共享同一个ID的情况
     */
    private static String getContactKey(Contact contact) {
        if (contact == null) {
            return null;
        }
        String id = contact.getId() != null ? contact.getId() : "";
        String phone = contact.getPhoneNumber() != null ? contact.getPhoneNumber() : "";
        return id + "|" + phone; // 使用 | 分隔符，因为电话号码中不会包含这个字符
    }
    
    public interface OnContactsChangedListener {
        void onContactsChanged(List<Contact> selectedContacts);
        void onConfirm(List<Contact> selectedContacts);
    }
    
    public static SelectedContactsBottomSheetDialog newInstance(
            List<Contact> selectedContacts, 
            OnContactsChangedListener listener) {
        Log.d(TAG, "newInstance: 创建对话框实例");
        SelectedContactsBottomSheetDialog dialog = new SelectedContactsBottomSheetDialog();
        dialog.setSelectedContacts(selectedContacts);
        dialog.setListener(listener);
        Log.d(TAG, "newInstance: 已设置选中联系人数量=" + (selectedContacts != null ? selectedContacts.size() : 0));
        return dialog;
    }
    
    public void setSelectedContacts(List<Contact> selectedContacts) {
        Log.d(TAG, "setSelectedContacts: 开始设置选中联系人");
        this.selectedContactIds = new HashSet<>();
        if (selectedContacts != null) {
            for (Contact contact : selectedContacts) {
                if (contact != null) {
                    String key = getContactKey(contact);
                    if (key != null) {
                        selectedContactIds.add(key);
                        Log.d(TAG, "setSelectedContacts: 添加联系人 - name=" + contact.getName() + ", key=" + key);
                    }
                }
            }
            Log.d(TAG, "setSelectedContacts: 已设置 " + selectedContactIds.size() + " 个选中联系人（使用ID+电话号码组合）");
        } else {
            Log.d(TAG, "setSelectedContacts: 选中联系人列表为null");
        }
    }
    
    public void setListener(OnContactsChangedListener listener) {
        this.listener = listener;
    }
    
    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreateDialog: 创建对话框");
        try {
            // 在 onCreateDialog 时，requireContext() 应该是可用的
            Context context = requireContext();
            // 使用 BottomSheetDialog 并设置正确的主题
            BottomSheetDialog dialog = new BottomSheetDialog(context, R.style.Theme_SMSSender_BottomSheet);
            Log.d(TAG, "onCreateDialog: 对话框创建成功");
            return dialog;
        } catch (IllegalStateException e) {
            Log.e(TAG, "onCreateDialog: requireContext()失败，尝试使用getContext()", e);
            // 如果 requireContext() 失败，尝试使用 getContext()
            Context context = getContext();
            if (context != null) {
                try {
                    return new BottomSheetDialog(context, R.style.Theme_SMSSender_BottomSheet);
                } catch (Exception e2) {
                    Log.e(TAG, "onCreateDialog: 使用自定义主题失败，使用默认主题", e2);
                    return new BottomSheetDialog(context);
                }
            }
            // 最后的回退方案：使用父类默认实现
            Log.w(TAG, "onCreateDialog: 所有尝试都失败，使用父类默认实现");
            return super.onCreateDialog(savedInstanceState);
        } catch (Exception e) {
            Log.e(TAG, "onCreateDialog: 创建对话框时发生异常", e);
            // 异常情况下的回退方案
            try {
                Context context = getContext();
                if (context != null) {
                    return new BottomSheetDialog(context);
                }
            } catch (Exception e2) {
                Log.e(TAG, "onCreateDialog: 回退方案也失败", e2);
            }
            return super.onCreateDialog(savedInstanceState);
        }
    }
    
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView: 开始创建视图");
        View view = null;
        try {
            view = inflater.inflate(R.layout.bottom_sheet_selected_contacts, container, false);
            Log.d(TAG, "onCreateView: inflate完成");
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: inflate失败", e);
            return null;
        }
        
        // 初始化视图
        try {
            rvContacts = view.findViewById(R.id.rvContacts);
            etSearch = view.findViewById(R.id.etSearch);
            tvStats = view.findViewById(R.id.tvStats);
            tvSelectedCountBottom = view.findViewById(R.id.tvSelectedCountBottom);
            btnSelectAll = view.findViewById(R.id.btnSelectAll);
            btnClearAll = view.findViewById(R.id.btnClearAll);
            btnConfirm = view.findViewById(R.id.btnConfirm);
            btnCancel = view.findViewById(R.id.btnCancel);
            Log.d(TAG, "onCreateView: findViewById完成");
            
            // 检查关键视图是否找到
            if (rvContacts == null) {
                Log.e(TAG, "onCreateView: rvContacts为null");
            }
            if (etSearch == null) {
                Log.e(TAG, "onCreateView: etSearch为null");
            }
            if (tvStats == null) {
                Log.e(TAG, "onCreateView: tvStats为null");
            }
            if (tvSelectedCountBottom == null) {
                Log.e(TAG, "onCreateView: tvSelectedCountBottom为null");
            }
            if (btnSelectAll == null) {
                Log.e(TAG, "onCreateView: btnSelectAll为null");
            }
            if (btnClearAll == null) {
                Log.e(TAG, "onCreateView: btnClearAll为null");
            }
            if (btnConfirm == null) {
                Log.e(TAG, "onCreateView: btnConfirm为null");
            }
            if (btnCancel == null) {
                Log.e(TAG, "onCreateView: btnCancel为null");
            }
            Log.d(TAG, "onCreateView: 视图初始化完成");
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: findViewById失败", e);
            return view;
        }
        
        try {
            // 确保 selectedContactIds 已初始化
            if (selectedContactIds == null) {
                selectedContactIds = new HashSet<>();
                Log.d(TAG, "onCreateView: selectedContactIds为null，已重新初始化");
            } else {
                Log.d(TAG, "onCreateView: selectedContactIds已存在，包含 " + selectedContactIds.size() + " 个联系人");
            }
            
            // 加载所有联系人 - 使用view.getContext()而不是getContext()
            Context loadContext = view.getContext();
            if (loadContext != null) {
                loadAllContacts(loadContext);
                Log.d(TAG, "onCreateView: loadAllContacts完成");
            } else {
                Log.e(TAG, "onCreateView: view.getContext()为null，无法加载联系人");
                allContacts = new ArrayList<>();
            }
            
            // 初始化RecyclerView - 显示所有联系人，但标记已选中的
            if (allContacts == null) {
                allContacts = new ArrayList<>();
            }
            filteredContacts = new ArrayList<>(allContacts);
            Log.d(TAG, "onCreateView: 准备显示联系人，总数=" + filteredContacts.size());
            sortContacts(filteredContacts);
            Log.d(TAG, "onCreateView: sortContacts完成");
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: 数据初始化失败", e);
            return view;
        }
        
        try {
            adapter = new ContactBottomSheetAdapter(filteredContacts, selectedContactIds, new ContactBottomSheetAdapter.OnContactClickListener() {
            @Override
            public void onContactCheckedChanged(Contact contact, boolean isChecked) {
                String contactKey = getContactKey(contact);
                String contactName = contact != null ? contact.getName() : "null";
                Log.d(TAG, "onContactCheckedChanged: 联系人 " + contactName + " (Key: " + contactKey + ") 选中状态=" + isChecked);
                if (isChecked) {
                    if (contactKey != null) {
                        selectedContactIds.add(contactKey);
                    }
                } else {
                    if (contactKey != null) {
                        selectedContactIds.remove(contactKey);
                    }
                }
                Log.d(TAG, "onContactCheckedChanged: 当前选中数量=" + selectedContactIds.size());
                updateUI();
                if (listener != null) {
                    List<Contact> selected = getSelectedContacts();
                    listener.onContactsChanged(selected);
                }
            }
            
            @Override
            public void onContactDelete(Contact contact) {
                String contactKey = getContactKey(contact);
                String contactName = contact != null ? contact.getName() : "null";
                Log.d(TAG, "onContactDelete: 删除联系人 " + contactName + " (Key: " + contactKey + ")");
                if (contactKey != null) {
                    selectedContactIds.remove(contactKey);
                }
                updateUI();
                adapter.notifyDataSetChanged();
                if (listener != null) {
                    List<Contact> selected = getSelectedContacts();
                    listener.onContactsChanged(selected);
                }
            }
        });
            Log.d(TAG, "onCreateView: Adapter创建完成");
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: Adapter创建失败", e);
            return view;
        }
        
        // 使用 view.getContext() 而不是 getContext()，避免在 onCreateView 时返回 null
        try {
            Context context = view.getContext();
            if (context != null) {
                if (rvContacts != null) {
                    rvContacts.setLayoutManager(new LinearLayoutManager(context));
                    rvContacts.setAdapter(adapter);
                    Log.d(TAG, "onCreateView: RecyclerView初始化完成，适配器已设置");
                } else {
                    Log.e(TAG, "onCreateView: rvContacts为null，无法设置RecyclerView");
                }
            } else {
                Log.e(TAG, "onCreateView: Context is null，无法设置RecyclerView");
            }
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: RecyclerView初始化失败", e);
            return view;
        }
        
        // 搜索功能
        try {
            if (etSearch != null) {
                etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
            
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                String query = s != null ? s.toString() : "";
                Log.d(TAG, "onTextChanged: 搜索关键词=" + query);
                filterContacts(query);
            }
            
            @Override
            public void afterTextChanged(Editable s) {}
                });
                Log.d(TAG, "onCreateView: 搜索监听器设置完成");
            } else {
                Log.e(TAG, "onCreateView: etSearch为null，无法设置搜索监听器");
            }
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: 设置搜索监听器失败", e);
        }
        
        // 全选按钮
        try {
            if (btnSelectAll != null) {
                btnSelectAll.setOnClickListener(v -> {
            boolean allSelected = isAllSelected();
            Log.d(TAG, "btnSelectAll: 点击全选按钮，当前全部选中状态=" + allSelected);
            if (allSelected) {
                deselectAll();
            } else {
                selectAll();
            }
                });
            } else {
                Log.e(TAG, "onCreateView: btnSelectAll为null，无法设置点击监听器");
            }
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: 设置全选按钮监听器失败", e);
        }
        
        // 清空按钮
        try {
            if (btnClearAll != null) {
                btnClearAll.setOnClickListener(v -> {
                    Log.d(TAG, "btnClearAll: 点击清空按钮");
                    deselectAll();
                });
            } else {
                Log.e(TAG, "onCreateView: btnClearAll为null，无法设置点击监听器");
            }
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: 设置清空按钮监听器失败", e);
        }
        
        // 确定按钮
        try {
            if (btnConfirm != null) {
                btnConfirm.setOnClickListener(v -> {
                    List<Contact> selected = getSelectedContacts();
                    Log.d(TAG, "btnConfirm: 点击确定按钮，确认选中 " + selected.size() + " 个联系人");
                    if (listener != null) {
                        listener.onConfirm(selected);
                    }
                    dismiss();
                });
            } else {
                Log.e(TAG, "onCreateView: btnConfirm为null，无法设置点击监听器");
            }
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: 设置确定按钮监听器失败", e);
        }
        
        // 取消按钮
        try {
            if (btnCancel != null) {
                btnCancel.setOnClickListener(v -> {
                    Log.d(TAG, "btnCancel: 点击取消按钮");
                    dismiss();
                });
            } else {
                Log.e(TAG, "onCreateView: btnCancel为null，无法设置点击监听器");
            }
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: 设置取消按钮监听器失败", e);
        }
        
        // 初始化UI
        try {
            updateUI();
            Log.d(TAG, "onCreateView: updateUI完成");
        } catch (Exception e) {
            Log.e(TAG, "onCreateView: updateUI失败", e);
        }
        
        Log.d(TAG, "onCreateView: 视图创建完成");
        return view;
    }
    
    private void loadAllContacts(Context context) {
        Log.d(TAG, "loadAllContacts: 开始加载所有联系人");
        if (context == null) {
            Log.w(TAG, "loadAllContacts: Context为null，无法加载联系人");
            allContacts = new ArrayList<>();
            return;
        }
        try {
            DataManager dataManager = DataManager.getInstance(context);
            allContacts = dataManager.getContacts();
            if (allContacts == null) {
                Log.w(TAG, "loadAllContacts: 获取的联系人列表为null");
                allContacts = new ArrayList<>();
            } else {
                Log.d(TAG, "loadAllContacts: 成功加载 " + allContacts.size() + " 个联系人");
            }
        } catch (Exception e) {
            Log.e(TAG, "loadAllContacts: 加载联系人时发生错误", e);
            allContacts = new ArrayList<>();
        }
    }
    
    private void filterContacts(String query) {
        if (filteredContacts == null) {
            filteredContacts = new ArrayList<>();
        }
        if (allContacts == null) {
            allContacts = new ArrayList<>();
        }
        
        filteredContacts.clear();
        if (query == null || query.trim().isEmpty()) {
            filteredContacts.addAll(allContacts);
            Log.d(TAG, "filterContacts: 搜索关键词为空，显示所有 " + filteredContacts.size() + " 个联系人");
        } else {
            String lowerQuery = query.toLowerCase(Locale.getDefault());
            int matchCount = 0;
            for (Contact contact : allContacts) {
                if (contact != null) {
                    String name = contact.getName() != null ? contact.getName().toLowerCase(Locale.getDefault()) : "";
                    String phone = contact.getPhoneNumber() != null ? contact.getPhoneNumber().toLowerCase(Locale.getDefault()) : "";
                    if (name.contains(lowerQuery) || phone.contains(lowerQuery)) {
                        filteredContacts.add(contact);
                        matchCount++;
                    }
                }
            }
            Log.d(TAG, "filterContacts: 搜索关键词=\"" + query + "\"，匹配到 " + matchCount + " 个联系人");
        }
        sortContacts(filteredContacts);
        if (adapter != null) {
            adapter.notifyDataSetChanged();
        }
        updateUI();
    }
    
    private void sortContacts(List<Contact> contacts) {
        if (contacts == null) {
            return;
        }
        // 确保 selectedContactIds 已初始化
        if (selectedContactIds == null) {
            selectedContactIds = new HashSet<>();
        }
        Collections.sort(contacts, new Comparator<Contact>() {
            @Override
            public int compare(Contact c1, Contact c2) {
                if (c1 == null && c2 == null) return 0;
                if (c1 == null) return 1;
                if (c2 == null) return -1;
                
                // 首先按选中状态排序（选中的在前）
                String key1 = getContactKey(c1);
                String key2 = getContactKey(c2);
                boolean c1Selected = key1 != null && selectedContactIds.contains(key1);
                boolean c2Selected = key2 != null && selectedContactIds.contains(key2);
                if (c1Selected != c2Selected) {
                    return c1Selected ? -1 : 1;
                }
                // 然后按姓名排序
                String name1 = c1.getName() != null ? c1.getName() : "";
                String name2 = c2.getName() != null ? c2.getName() : "";
                return name1.compareToIgnoreCase(name2);
            }
        });
    }
    
    private void selectAll() {
        if (filteredContacts == null || selectedContactIds == null) {
            Log.w(TAG, "selectAll: filteredContacts或selectedContactIds为null，无法执行全选");
            return;
        }
        int selectedCount = 0;
        for (Contact contact : filteredContacts) {
            if (contact != null) {
                String key = getContactKey(contact);
                if (key != null) {
                    selectedContactIds.add(key);
                    selectedCount++;
                }
            }
        }
        Log.d(TAG, "selectAll: 全选了 " + selectedCount + " 个联系人，当前总选中数=" + selectedContactIds.size());
        adapter.notifyDataSetChanged();
        updateUI();
        if (listener != null) {
            List<Contact> selected = getSelectedContacts();
            listener.onContactsChanged(selected);
        }
    }
    
    private void deselectAll() {
        if (filteredContacts == null || selectedContactIds == null) {
            Log.w(TAG, "deselectAll: filteredContacts或selectedContactIds为null，无法执行清空");
            return;
        }
        int deselectedCount = 0;
        for (Contact contact : filteredContacts) {
            if (contact != null) {
                String key = getContactKey(contact);
                if (key != null && selectedContactIds.remove(key)) {
                    deselectedCount++;
                }
            }
        }
        Log.d(TAG, "deselectAll: 清空了 " + deselectedCount + " 个联系人，当前总选中数=" + selectedContactIds.size());
        adapter.notifyDataSetChanged();
        updateUI();
        if (listener != null) {
            List<Contact> selected = getSelectedContacts();
            listener.onContactsChanged(selected);
        }
    }
    
    private boolean isAllSelected() {
        if (filteredContacts == null || filteredContacts.isEmpty() || selectedContactIds == null) {
            return false;
        }
        for (Contact contact : filteredContacts) {
            if (contact != null) {
                String key = getContactKey(contact);
                if (key == null || !selectedContactIds.contains(key)) {
                    return false;
                }
            }
        }
        return true;
    }
    
    private List<Contact> getSelectedContacts() {
        List<Contact> selected = new ArrayList<>();
        if (allContacts == null || selectedContactIds == null) {
            Log.w(TAG, "getSelectedContacts: allContacts或selectedContactIds为null");
            return selected;
        }
        for (Contact contact : allContacts) {
            if (contact != null) {
                String key = getContactKey(contact);
                if (key != null && selectedContactIds.contains(key)) {
                    selected.add(contact);
                }
            }
        }
        Log.d(TAG, "getSelectedContacts: 获取到 " + selected.size() + " 个选中联系人");
        return selected;
    }
    
    private void updateUI() {
        if (filteredContacts == null || selectedContactIds == null) {
            Log.w(TAG, "updateUI: filteredContacts或selectedContactIds为null，无法更新UI");
            return;
        }
        try {
            int totalCount = filteredContacts.size();
            // 计算当前筛选结果中被选中的数量
            int selectedCountInFiltered = 0;
            for (Contact contact : filteredContacts) {
                if (contact != null) {
                    String key = getContactKey(contact);
                    if (key != null && selectedContactIds.contains(key)) {
                        selectedCountInFiltered++;
                    }
                }
            }
            // 总选择数（所有联系人中被选中的总数）
            int totalSelectedCount = getSelectedContacts().size();
            
            Log.d(TAG, "updateUI: 更新UI - 筛选结果总数=" + totalCount + 
                    ", 筛选结果中选中=" + selectedCountInFiltered + 
                    ", 总选中数=" + totalSelectedCount);
            
            // 更新统计信息
            if (tvStats != null) {
                tvStats.setText("共 " + totalCount + " 个联系人");
            } else {
                Log.e(TAG, "updateUI: tvStats为null");
            }
            if (tvSelectedCountBottom != null) {
                tvSelectedCountBottom.setText("已选择 " + totalSelectedCount + " 个");
            } else {
                Log.e(TAG, "updateUI: tvSelectedCountBottom为null");
            }
            
            // 更新全选按钮文本
            if (btnSelectAll != null) {
                if (isAllSelected() && !filteredContacts.isEmpty()) {
                    btnSelectAll.setText("取消全选");
                } else {
                    btnSelectAll.setText("全选");
                }
            } else {
                Log.e(TAG, "updateUI: btnSelectAll为null");
            }
        } catch (Exception e) {
            Log.e(TAG, "updateUI: 更新UI时发生异常", e);
        }
    }
    
    /**
     * BottomSheet中的联系人列表适配器
     */
    static class ContactBottomSheetAdapter extends RecyclerView.Adapter<ContactBottomSheetAdapter.ViewHolder> {
        
        private List<Contact> contacts;
        private Set<String> selectedContactIds;
        private OnContactClickListener listener;
        
        interface OnContactClickListener {
            void onContactCheckedChanged(Contact contact, boolean isChecked);
            void onContactDelete(Contact contact);
        }
        
        ContactBottomSheetAdapter(List<Contact> contacts, Set<String> selectedContactIds, OnContactClickListener listener) {
            this.contacts = contacts;
            this.selectedContactIds = selectedContactIds;
            this.listener = listener;
        }
        
        @NonNull
        @Override
        public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_contact_bottom_sheet, parent, false);
            return new ViewHolder(view);
        }
        
        @Override
        public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
            Contact contact = contacts.get(position);
            if (contact == null) {
                return;
            }
            
            holder.tvName.setText(contact.getName() != null ? contact.getName() : "");
            holder.tvPhoneNumber.setText(contact.getPhoneNumber() != null ? contact.getPhoneNumber() : "");
            
            // 确保 selectedContactIds 不为 null，使用ID+电话号码组合作为唯一键
            String contactKey = getContactKey(contact);
            boolean isSelected = contactKey != null && selectedContactIds != null && selectedContactIds.contains(contactKey);
            
            // 先移除监听器，避免重复触发
            holder.checkBox.setOnCheckedChangeListener(null);
            holder.checkBox.setChecked(isSelected);
            
            // 选中状态显示删除图标
            holder.ivDelete.setVisibility(isSelected ? View.VISIBLE : View.GONE);
            
            // 设置CheckBox点击事件（在设置checked之后）
            holder.checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
                if (listener != null && contactKey != null) {
                    listener.onContactCheckedChanged(contact, isChecked);
                }
            });
            
            // 删除图标点击事件
            holder.ivDelete.setOnClickListener(v -> {
                if (listener != null && contactKey != null) {
                    listener.onContactDelete(contact);
                }
            });
            
            // 整个item点击事件
            holder.itemView.setOnClickListener(v -> {
                boolean newChecked = !holder.checkBox.isChecked();
                holder.checkBox.setChecked(newChecked);
            });
        }
        
        @Override
        public int getItemCount() {
            return contacts != null ? contacts.size() : 0;
        }
        
        static class ViewHolder extends RecyclerView.ViewHolder {
            CheckBox checkBox;
            TextView tvName;
            TextView tvPhoneNumber;
            ImageView ivDelete;
            
            ViewHolder(View itemView) {
                super(itemView);
                checkBox = itemView.findViewById(R.id.checkBox);
                tvName = itemView.findViewById(R.id.tvName);
                tvPhoneNumber = itemView.findViewById(R.id.tvPhoneNumber);
                ivDelete = itemView.findViewById(R.id.ivDelete);
            }
        }
    }
}

